#include "Core.h"

std::list<iFile*> iFile::s_OpenFiles;

iFile::iFile() {
	s_OpenFiles.push_back(this);
}

iFile::~iFile() {
	s_OpenFiles.remove(this);
}

void iFile::SetFilePath(std::string NewFilePath) {
	strFilePath = NewFilePath;
}

std::string iFile::GetFilePath() {
	return strFilePath;
}

bool iFile::CheckFile(void) {
	WIN32_FILE_ATTRIBUTE_DATA sFileAttributes;
	GetFileAttributesEx(strFilePath.c_str(), GetFileExInfoStandard, &sFileAttributes);
	bool bNeedToReopen = LastWrite.dwHighDateTime != sFileAttributes.ftLastWriteTime.dwHighDateTime &&
						 LastWrite.dwLowDateTime != sFileAttributes.ftLastWriteTime.dwLowDateTime;

	if(bNeedToReopen)
		ReopenFile();

	return bNeedToReopen;
}

void iFile::CheckAllFiles(void) {
	for each (iFile* a in s_OpenFiles)
		a->CheckFile();
}